home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form frmTrayIcon
- Appearance = 0 'Flat
- BackColor = &H80000005&
- BorderStyle = 0 'None
- ClientHeight = 1620
- ClientLeft = 4155
- ClientTop = 4590
- ClientWidth = 2700
- Height = 2025
- Icon = "frmTrayIcon.frx":0000
- Left = 4095
- LinkTopic = "Form1"
- LockControls = -1 'True
- ScaleHeight = 1620
- ScaleWidth = 2700
- ShowInTaskbar = 0 'False
- Top = 4245
- Visible = 0 'False
- Width = 2820
- Attribute VB_Name = "frmTrayIcon"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- Private Type NOTIFYICONDATA
- cbSize As Long
- hwnd As Long
- uId As Long
- uFlags As Long
- ucallbackMessage As Long
- hIcon As Long
- szTip As String * 64
- End Type
- Private Const NIM_ADD = &H0
- Private Const NIM_MODIFY = &H1
- Private Const NIM_DELETE = &H2
- Private Const WM_MOUSEMOVE = &H200
- Private Const NIF_MESSAGE = &H1
- Private Const NIF_ICON = &H2
- Private Const NIF_TIP = &H4
- Private IconIsOn As Boolean
- Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
- Private t As NOTIFYICONDATA
- Public Owner As Form
- Public ShowTray As Boolean
- ' Set's which object to call "TrayIconCallback(msg As Long)" in.
- Public Sub SetCallback(ob As Object)
- Set Owner = ob
- End Sub
- ' Turns the Trayicon on and off.
- ' Note: the Icon, and ToolTip are taken from the
- ' form's icon and caption respectively.
- Public Sub Update(IconOn As Boolean)
- If IconOn Then
- t.cbSize = Len(t)
- t.hwnd = Me.hwnd
- t.uId = 1&
- t.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
- If Me.Caption <> "" Then
- t.uFlags = t.uFlags Or NIF_TIP
- End If
- t.ucallbackMessage = WM_MOUSEMOVE
- t.hIcon = Me.icon
- t.szTip = Me.Caption & Chr$(0)
-
- If Not IconIsOn Then
- Shell_NotifyIcon NIM_ADD, t
- Else
- Shell_NotifyIcon NIM_MODIFY, t
- End If
- IconIsOn = True
- Else
- If IconIsOn Then
- t.cbSize = Len(t)
- t.hwnd = Me.hwnd
- t.uId = 1&
- Shell_NotifyIcon NIM_DELETE, t
- End If
- IconIsOn = False
- End If
- End Sub
- Private Sub Form_Load()
- IconIsOn = False
- End Sub
- Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
- Static rec As Boolean, msg As Long
- msg = X / Screen.TwipsPerPixelX
- If rec = False Then
- rec = True
-
- ' Ignore an error if the call to
- ' Owner.TrayIconCallback fails
- On Error Resume Next
- If msg >= WM_LBUTTONDOWN And msg <= WM_RBUTTONDBLCLK Then
- Call Owner.TrayIconCallback(msg)
- End If
-
- rec = False
- End If
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- Me.Update False
- End Sub
-